package com.hxc.interest.service.impl;

import java.util.List;
import com.hxc.common.utils.DateUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hxc.interest.mapper.TReactionDiscussMapper;
import com.hxc.interest.domain.TReactionDiscuss;
import com.hxc.interest.service.ITReactionDiscussService;

/**
 * 用户评论信息Service业务层处理
 * 
 * @author hxc
 * @date 2021-08-18
 */
@Service
public class TReactionDiscussServiceImpl implements ITReactionDiscussService 
{
    @Autowired
    private TReactionDiscussMapper tReactionDiscussMapper;

    /**
     * 查询用户评论信息
     * 
     * @param id 用户评论信息主键
     * @return 用户评论信息
     */
    @Override
    public TReactionDiscuss selectTReactionDiscussById(Long id)
    {
        TReactionDiscuss reactionDiscuss = tReactionDiscussMapper.selectTReactionDiscussById(id);
        if(ObjectUtils.isNotEmpty(reactionDiscuss)){
            //判断上传图片是否为null
            if(StringUtils.isNotBlank(reactionDiscuss.getImgUrl())){
                reactionDiscuss.setImgList(reactionDiscuss.getImgUrl().split(","));
            }
        }
        return reactionDiscuss;
    }

    /**
     * 查询用户评论信息列表
     * 
     * @param tReactionDiscuss 用户评论信息
     * @return 用户评论信息
     */
    @Override
    public List<TReactionDiscuss> selectTReactionDiscussList(TReactionDiscuss tReactionDiscuss)
    {
        List<TReactionDiscuss> reactionDiscussList = tReactionDiscussMapper.selectTReactionDiscussList(tReactionDiscuss);
        if(reactionDiscussList.size() > 0){
            reactionDiscussList.forEach(reactionDiscuss -> {
                //判断上传图片是否为 null
                if(StringUtils.isNotBlank(reactionDiscuss.getImgUrl())){
                    reactionDiscuss.setImgList(reactionDiscuss.getImgUrl().split(","));
                }
            });
        }
        return reactionDiscussList;
    }

    /**
     * 新增用户评论信息
     * 
     * @param tReactionDiscuss 用户评论信息
     * @return 结果
     */
    @Override
    public int insertTReactionDiscuss(TReactionDiscuss tReactionDiscuss)
    {
        tReactionDiscuss.setCreateTime(DateUtils.getNowDate());
        return tReactionDiscussMapper.insertTReactionDiscuss(tReactionDiscuss);
    }

    /**
     * 修改用户评论信息
     * 
     * @param tReactionDiscuss 用户评论信息
     * @return 结果
     */
    @Override
    public int updateTReactionDiscuss(TReactionDiscuss tReactionDiscuss)
    {
        return tReactionDiscussMapper.updateTReactionDiscuss(tReactionDiscuss);
    }

    /**
     * 批量删除用户评论信息
     * 
     * @param ids 需要删除的用户评论信息主键
     * @return 结果
     */
    @Override
    public int deleteTReactionDiscussByIds(Long[] ids)
    {
        return tReactionDiscussMapper.deleteTReactionDiscussByIds(ids);
    }

    /**
     * 删除用户评论信息信息
     * 
     * @param id 用户评论信息主键
     * @return 结果
     */
    @Override
    public int deleteTReactionDiscussById(Long id)
    {
        return tReactionDiscussMapper.deleteTReactionDiscussById(id);
    }
}
